package com.hd123.rumba.gwt.widget.client;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

public class DoubleLabeledTextBox extends HorizontalPanel implements LabeledBox {
  private Label label, label2;
  private TextBox textBox, textBox2;
  private String caption, caption2;
  private boolean required = false;
  private boolean readOnly = false;

  public DoubleLabeledTextBox() {
    super();
    setSpacing(4);

    label = new Label();
    label.setWidth("100px");
    add(label);
    setCellVerticalAlignment(label, HorizontalPanel.ALIGN_MIDDLE);

    textBox = createInputBox();
    add(textBox);
    setCellVerticalAlignment(textBox, HorizontalPanel.ALIGN_MIDDLE);

    label2 = new Label();
    add(label2);
    setCellVerticalAlignment(label2, HorizontalPanel.ALIGN_MIDDLE);

    textBox2 = createInputBox();
    add(textBox2);
    setCellVerticalAlignment(textBox2, HorizontalPanel.ALIGN_MIDDLE);
  }

  public DoubleLabeledTextBox(String caption1, String caption2) {
    this();
    setCaption(caption1);
    setCaption2(caption2);
  }
  
  protected TextBox createInputBox() {
    return new TextBoxE();
  }

  public String getCaption() {
    return caption;
  }

  public void setCaption(String caption) {
    this.caption = caption;
    if (required && !readOnly)
      DOM.setInnerHTML(label.getElement(), this.caption + "<font color='red'>*</font>");
    else
      label.setText(caption);
  }

  public String getCaption2() {
    return caption2;
  }

  public void setCaption2(String caption) {
    caption2 = caption;
    label2.setText(caption2);
  }

  public String getText() {
    return textBox.getText();
  }

  public void setText(String text) {
    textBox.setText(text);
  }

  public String getText2() {
    return textBox2.getText();
  }

  public void setText2(String text) {
    textBox2.setText(text);
  }

  public boolean getReadOnly() {
    return readOnly;
  }

  public void setReadOnly(boolean b) {
    readOnly = b;
    setCaption(caption);
    textBox.setReadOnly(b);
    textBox2.setReadOnly(b);
  }

  public void setBoxMaxLength(int length) {
    textBox.setMaxLength(length);
  }

  public void setBoxWidth(String width) {
    textBox.setWidth(width);
  }

  public void setCaptionWidth(String width) {
    label.setWidth(width);
  }

  public void setBox2MaxLength(int length) {
    textBox2.setMaxLength(length);
  }

  public void setBox2Width(String width) {
    textBox2.setWidth(width);
  }

  public void setCaption2Width(String width) {
    label2.setWidth(width);
  }

  public void setRequired(boolean required) {
    this.required = required;
  }
}
